package models.common.entity;


import java.util.Date;
import java.util.Random;

import javax.persistence.Entity;
import javax.persistence.Transient;

import com.zhongan.zadeviceinfo.R.string;

import play.db.jpa.Model;

import common.constants.ConfConst;
import common.constants.Constants;
import common.utils.DateUtil;
import common.utils.Security;
/**
 * 债权债务表
 *@author xiaojun
 *@version 2017-4-14 下午2:17:27
 */
@Entity
public class t_creditor_right_debt extends Model{
	/**
	 * 构造器
	 */
	public t_creditor_right_debt(){};
	
	public t_creditor_right_debt(String contract_name_code,
			String debt_person_name, String debt_business_license_code,
			String debt_province, String remark, String contract_num,
			String invoice_num, double creditor_money, String currency,
			String voucher_remark, String pic_addr, Date statement_open_time,
			Date statement_time, String voucher_type, String voucher_code,
			double voucher_money, String voucher_currency,
			Date voucher_open_time, Date voucher_end_time, String debt_city,
			String debt_county, String creditor_name,
			String creditor_business_license_code, String creditor_province,
			String creditor_city, String creditor_county, Date checkin_time,
			String platform_account_code, long debt_com_id, long company_id,
			long register_id, long creditor_right_id, double rest_debt_money,
			int status, long lender_id, int type, String statement_time_str,
			String sign, String contract_datetime, String crightAddress,
			String debtAddress, String account_code) {
		super();
		this.contract_name_code = contract_name_code;
		this.debt_person_name = debt_person_name;
		this.debt_business_license_code = debt_business_license_code;
		this.debt_province = debt_province;
		this.remark = remark;
		this.contract_num = contract_num;
		this.invoice_num = invoice_num;
		this.creditor_money = creditor_money;
		this.currency = currency;
		this.voucher_remark = voucher_remark;
		this.pic_addr = pic_addr;
		this.statement_open_time = statement_open_time;
		this.statement_time = statement_time;
		this.voucher_type = voucher_type;
		this.voucher_code = voucher_code;
		this.voucher_money = voucher_money;
		this.voucher_currency = voucher_currency;
		this.voucher_open_time = voucher_open_time;
		this.voucher_end_time = voucher_end_time;
		this.debt_city = debt_city;
		this.debt_county = debt_county;
		this.creditor_name = creditor_name;
		this.creditor_business_license_code = creditor_business_license_code;
		this.creditor_province = creditor_province;
		this.creditor_city = creditor_city;
		this.creditor_county = creditor_county;
		this.checkin_time = checkin_time;
		this.platform_account_code = platform_account_code;
		this.debt_com_id = debt_com_id;
		this.company_id = company_id;
		this.register_id = register_id;
		this.creditor_right_id = creditor_right_id;
		this.rest_debt_money = rest_debt_money;
		this.status = status;
		this.lender_id = lender_id;
		this.type = type;
		this.statement_time_str = statement_time_str;
		this.sign = sign;
		this.contract_datetime = contract_datetime;
		this.crightAddress = crightAddress;
		this.debtAddress = debtAddress;
		this.account_code = account_code;
	}




	/**账款序号*/
    public String contract_name_code;
    
    /**债务人全称'*/
    public String debt_person_name;
    
    /**债务人统一信用代码*/
    public String debt_business_license_code;
    
    /**债务人所在的省*/
    public String debt_province;
    
    /**'账款描述' */
    public String remark;
    
    /**合同编号*/
    public String contract_num;
    
    /**发票号码*/
    public String invoice_num;
    
    
    
    /**账款金额 */
    public double creditor_money;
    
    /**账款币种*/
    public String currency;
    
    /**凭证备注*/
    public String voucher_remark;
    
    
    
    /**上传附件名称*/
    public String pic_addr;
    
    
    /**账款开始时间*/
    public Date statement_open_time;
    
    /**账款结算日期*/
    public Date statement_time;
    
    /**凭证类型*/
    public String voucher_type;
    
    /**凭证编号*/
    public String voucher_code;
    
    /**凭证金额*/
    public double voucher_money;
    
    /**账款凭证币种*/
    public String voucher_currency;
    
    /**凭证开始时间*/
    public Date voucher_open_time;
    
    /**凭证结算日期*/
    public Date voucher_end_time;
    
    
    /**债务人所在的市*/
    public String debt_city;
    
    /**债务人所在的区*/
    public String debt_county;
    
    /**债权人全称 */
    public String creditor_name;
    
    /**债权统一信用代码（三证合一）*/
    public String creditor_business_license_code;
    
    /**债权人所在的省*/
    public String creditor_province;
    
    /**债权人所在的市*/
    public String creditor_city;
    
    /**债权人所在的区*/
    public String creditor_county;
    
    
    /**登记时间 */
    public Date checkin_time;
    @Transient
    public String checkinTime;
    public String getCheckinTime(){
    	return  DateUtil.dateToString(this.checkin_time, "yyyy/MM/dd HH:mm:ss");
    }
    /**平台账款编号*/
    public String platform_account_code;
    
   
    /**债务人用户id */
    public long debt_com_id;
    
    /**债权人用户id */
    public long company_id;
    			
    /**登记人用户id*/
    public long register_id;

    /**账款id(本数据) */
    public long creditor_right_id;

    /**剩余账款金额*/
    public double rest_debt_money;
    
    /**‘0 待确认1 已取消 2 未确认 3已确认 ’*/
    public int status;
    
    /**放款人id*/
    public long lender_id;
    
    /**0 应付账款 1 应收账款*/
    public int type;
    
    /**'结算结束日期' */
	@Transient
	public String statement_time_str;
	
	public String getStatement_time_str(){
		return DateUtil.dateToString(statement_time, "yyyy/MM/dd");
	}
    
   
	 public CreditorRightDebtStatus getRightDebtStatus() {
		 CreditorRightDebtStatus status = CreditorRightDebtStatus.getEnum(this.status);
		
		 return status;
	}
	 public CreditorRightDebtPath getRightDebtPath() {
		 CreditorRightDebtPath path = CreditorRightDebtPath.getEnum(this.status);
		 
		 return path;
	 }


	 /**
   	 * 债权的状态
   	 *
   	 * @description 
   	 *
   	 * @author xiaojun
   	 * @createDate 2017年4月15日
   	 */
   	public enum CreditorRightDebtStatus {
   		/**	0 待确认1 已取消 2 未确认 3已确认 4 已绑定  5 已质押 6 已失效 7未申请’*/
   		/** 待确认 */
   		TBC(0, "待确认"),
   		
   		/** 已取消 */
   		CANCEL(1, "已取消"),
   		
   		/** 未确认*/
   		UNCONFIRMED(2, "未确认"), 
   		
   		/** 已确认*/
   		CONFIRM(3, "已确认"),
   		
   		/** 已绑定 */
   		REGISTER(4, "已绑定"),	
   		 
   		/** 已质押 */
   		FINANCING(5, "已质押"),
   		
   		/** 已失效*//*
   		 LOSE_EFFICACY(6, "已失效"),*/
   		 
   		/**未申请*/
   		NOT_APPLY(7, "未申请");
   		
   		
   		/** 状态 */
   		public int code;
   		
   		/** 值 */
   		public String value;
   		
   		private CreditorRightDebtStatus(int code, String value){
   			this.code = code;
   			this.value = value;
   		}
   		
   		public static CreditorRightDebtStatus getEnum(int code){
   			CreditorRightDebtStatus[] bidstatus = CreditorRightDebtStatus.values();
   			for(CreditorRightDebtStatus income:bidstatus){
   				if(income.code == code){
   					
   					return income;
   				}
   			}
   			
   			return null;
   		}
   	}
   	/**
   	 * 债权的状态
   	 *
   	 * @description 
   	 *
   	 * @author xiaojun
   	 * @createDate 2017年4月15日
   	 */
   	public enum CreditorRightDebtPath {
   		/**	0 待确认1 已取消 2 未确认 3已确认 4 已绑定  5 已质押 6 已失效 7未申请’*/
   		/** 待确认 */
   		TBC(0,"dqr"),
   		
   		/** 已取消 */
   		CANCEL(1,"yqx"),
   		
   		/** 未确认*/
   		UNCONFIRMED(2,"wqr"), 
   		
   		/** 已确认*/
   		CONFIRM(3,"yqr"),
   		
   		/** 已绑定 */
   		REGISTER(4,"ybd"),	
   		
   		/** 已质押 */
   		FINANCING(5,"yzy"),
   		
   		/** 已失效*//*
   		 LOSE_EFFICACY(6, "已失效"),*/
   		
   		/**未申请*/
   		NOT_APPLY(7,"wsq");
   		
   		
   		/** 状态 */
   		public int code;
   		
   		
   		/** 微信端图片路径*/
   		public String path;
   		
   		
   		private CreditorRightDebtPath(int code,String path){
   			this.code = code;
   			this.path = path;
   		}
   		
   		public static CreditorRightDebtPath getEnum(int code){
   			CreditorRightDebtPath[] bidstatus = CreditorRightDebtPath.values();
   			for(CreditorRightDebtPath income:bidstatus){
   				if(income.code == code){
   					
   					return income;
   				}
   			}
   			
   			return null;
   		}
   	}
	/**当前表加密id*/
    @Transient
    public String sign;
    public String getSign(){
    	return Security.addSign(this.id, Constants.BID_ID_SIGN, ConfConst.ENCRYPTION_KEY_DES);
    }
    
    /**当前状态路径*/
    @Transient
    public String statustURl;
    public String getStatustURl(){
    	String url =  "/public/wechat/image/"+getRightDebtPath().path+".png";
    	
    	return url;
    }
    
    /**账款账期*/
    @Transient
    public String contract_datetime;
    
    public int getContract_datetime(){
    	if (statement_open_time == null || statement_time == null) {
			return -1;
		}
    	return DateUtil.getDaysDiffFloor(statement_open_time,statement_time);
    }
   @Transient
   public String crightAddress;
   public String getCrightAddress(){
	   String address = "";
	   if (this.creditor_province != null) {
		   address += this.debt_province ;
	   }
	   if (this.creditor_city != null) {
		   address += this.creditor_city;
	   }
	   if (this.creditor_county != null) {
		   address += this.creditor_county;
	   }
	   return  address;
   }
   
   @Transient
   public String debtAddress;
   public String getDebtAddress(){
	   String address = "";
	   if (this.debt_province != null) {
		   address += this.debt_province ;
	   }
	   if (this.debt_city != null) {
		   address += this.debt_city;
	   }
	   if (this.debt_county != null) {
		   address += this.debt_county;
	   }
	   return  address;
   }
   
   
//   展示不重复的账款序号
   @Transient
   public String account_code;
   
   public String getAccount_code(){
	   Random random = new Random();
	   String account_code = this.id + "";
	   /*if (this.id != null && this.id > 0) {
		   account_code += random.nextInt(10) ;
	   }*/
	   
	   return  account_code;
   }
}
